package com.usian.admin.controller.v1;

import com.usian.admin.service.AdChannelService;
import com.usian.apis.admin.v1.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.PageResponseResult;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * [一句话描述该类的功能]
 *
 * @author : XvYiFan
 * @version : [v1.0]
 * @createTime : [2022/10/26 10:34]
 */
@RestController
@RequestMapping("/api/v1/AdChannel")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelService adChannelService;

    @Override
    @PostMapping("/list")
    public PageResponseResult findBySearch(@RequestBody ChannelDto channelDto) {
        return adChannelService.findBySearch(channelDto);
    }

    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel adChannel) {
        return adChannelService.saveAdchannel(adChannel);
    }

    @Override
    @PutMapping("/update/{id}")
    public ResponseResult update(@PathVariable("id") Integer id,@RequestBody AdChannel adChannel) {
        return adChannelService.update(id,adChannel);
    }

    @Override
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return adChannelService.deleteById(id);
    }

    /**
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/findOne/{id}")
    public ResponseResult findOne(@PathVariable("id") Integer id) {
        AdChannel adChannel =  adChannelService.getById(id);
        return ResponseResult.okResult(adChannel);
    }

    @Override
    public ResponseResult findAll() {
        return adChannelService.findAll();
    }
}
